import { http } from "@/utils/http";

export interface SubmissionListCommand extends BasePageQuery {
  id?: number;
  title?: string;
  status?: string;
  assessmentYear?: number;
  mainCategory?: string;
  subCategory?: string;
  itemCategory?: string;
  currentAuditLevel?: number;
  owner?: number;
}

/**
 * 绩效上报项分页响应
 * 对应 Java: SubmissionDTO.java
 */
export interface SubmissionPageResponse {
  id: number;
  creatorId: number;
  assessmentYear: number;
  mainCategory: string;
  subCategory: string;
  itemCategory: string;
  title: string;
  detailsJson: string;
  userReportedScore: number;
  status: string;
  currentAuditLevel: number;
  firstReviewerName: string;
  secondReviewerName: string;
  thirdReviewerName: string;
  rejectionReason: string;
  createTime: string; // Java Date 对应 string
  fileList?: string;
  ownerScore: number;
  owner?: number;
  allocationDetails?: string;
}

/**
 * 获取绩效上报项列表
 * 对应 Java: SubmissionController.java -> list()
 */
export function getSubmissionListApi(params: SubmissionListCommand) {
  return http.request<ResponseData<PageDTO<SubmissionPageResponse>>>(
    "get",
    "/performance/submission/list",
    {
      params
    }
  );
}

/**
 * 导出绩效上报项Excel
 * 对应 Java: SubmissionController.java -> export()
 */
export const exportSubmissionExcelApi = (
  params: SubmissionListCommand,
  fileName: string
) => {
  return http.download("/performance/submission/excel", fileName, {
    params
  });
};

/**
 * 获取绩效上报项详情
 * 对应 Java: SubmissionController.java -> getInfo()
 */
export function getSubmissionInfoApi(id: number) {
  return http.request<ResponseData<SubmissionPageResponse>>(
    "get",
    `/performance/submission/${id}`
  );
}

/**
 * 删除绩效上报项
 * 对应 Java: SubmissionController.java -> delete()
 * 注意: Java控制器使用了 @RequestBody List<Long> ids,
 * 所以我们使用 'data' 而不是 'params'。
 */
export const deleteSubmissionApi = (data: Array<number>) => {
  return http.request<ResponseData<void>>("delete", "/performance/submission", {
    data // 使用 data 来发送JSON数组 [1, 2, 3]
  });
};

/**
 * 新增绩效上报项命令
 * 对应 Java: AddSubmissionCommand.java
 */
export interface AddSubmissionCommand {
  assessmentYear: number;
  mainCategory: string;
  subCategory: string;
  itemCategory: string;
  title: string;
  userReportedScore: number;
  status?: string;
  currentAuditLevel?: number;
  rejectionReason?: string;
  fileList?: string;
  detailsJson?: string;
  creatorId?: number;
  allocationDetails?: string;
  ownerScore?: number;
}

/**
 * 新增绩效上报项
 * 对应 Java: SubmissionController.java -> add()
 */
export const addSubmissionApi = (data: AddSubmissionCommand) => {
  return http.request<ResponseData<void>>("post", "/performance/submission", {
    data
  });
};

/**
 * 更新绩效上报项命令
 * 对应 Java: UpdateSubmissionCommand.java
 */
export interface UpdateSubmissionCommand extends AddSubmissionCommand {
  id: number;
}

/**
 * 修改绩效上报项
 * 对应 Java: SubmissionController.java -> edit()
 */
export const updateSubmissionApi = (data: UpdateSubmissionCommand) => {
  return http.request<ResponseData<void>>("put", "/performance/submission", {
    data
  });
};

/**
 * 七牛云文件上传响应
 */
export interface QiniuUploadResponse {
  url: string;
  fileName: string;
}

/**
 * 七牛云文件上传
 */
export const uploadToQiniuApi = (data: FormData) => {
  return http.request<ResponseData<QiniuUploadResponse>>(
    "post",
    "/qiNiufile/uploadToQiniu",
    {
      data,
      headers: {
        "Content-Type": "multipart/form-data"
      }
    }
  );
};

/**
 * 批量提交绩效上报项
 * 对应 Java: SubmissionController.java -> batchSubmit()
 */
export const batchSubmitSubmissionApi = (data: Array<number>) => {
  return http.request<ResponseData<void>>("post", "/performance/submission/batchSubmit", {
    data // 使用 data 来发送JSON数组 [1, 2, 3]
  });
};

/**
 * 批量审核命令
 * 对应 Java: BatchReviewSubmissionCommand.java
 */
export interface BatchReviewSubmissionCommand {
  idList: Array<number>;
  approved: boolean;
  reason?: string;
}

/**
 * 批量审核绩效上报项
 * 对应 Java: SubmissionController.java -> batchReview()
 */
export const batchReviewSubmissionApi = (data: BatchReviewSubmissionCommand) => {
  return http.request<ResponseData<void>>("post", "/performance/submission/batchReview", {
    data
  });
};

/**
 * 导出文件信息
 * 对应 Java: SysFileDTO.java
 */
export interface SubmissionExportFileDTO {
  fileId?: number;
  fileName: string;
  createTime: string;
  dataCount?: number;
  url: string;
  fileSize?: number;
  remark?: string;
}

/**
 * 文件查询参数
 * 对应 Java: SysFileQuery.java
 */
export interface SysFileQuery extends BasePageQuery {
  bizType?: string;
}

/**
 * 异步导出绩效上报项
 * 对应 Java: SubmissionController.java -> asyncExport()
 */
export const asyncExportSubmissionApi = (data: SubmissionListCommand) => {
  return http.request<ResponseData<void>>("post", "/performance/submission/asyncExport", {
    data
  });
};

/**
 * 查询导出的绩效上报项Excel文件列表
 * 对应 Java: SubmissionController.java -> getExportFiles()
 */
export const getSubmissionExportFilesApi = (params: SysFileQuery) => {
  return http.request<ResponseData<PageDTO<SubmissionExportFileDTO>>>(
    "get",
    "/performance/submission/exportFiles",
    {
      params
    }
  );
};

